package com.xjx.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 统一错误码枚举
 *
 */
@AllArgsConstructor
@Getter
public enum ErrorCode {

    // ------------------- 通用成功/失败 -------------------
    SUCCESS(200, "操作成功"),
    FAILURE(500, "操作失败"), // 通用失败

    // ------------------- HTTP 状态码 (客户端错误 4xx) -------------------
    BAD_REQUEST(400, "参数错误"),
    UNAUTHORIZED(401, "登录失效，请重新登录"),
    FORBIDDEN(403, "权限不足，禁止访问"),
    NOT_FOUND(404, "请求的资源不存在"),
    METHOD_NOT_ALLOWED(405, "请求方法不被允许"),
    REQUEST_TIMEOUT(408, "请求超时"),
    CONFLICT(409, "资源冲突或数据已存在"),

    // ------------------- HTTP 状态码 (服务端错误 5xx) -------------------
    INTERNAL_SERVER_ERROR(500, "服务器内部异常，请稍后重试"),
    BAD_GATEWAY(502, "网关错误"),
    SERVICE_UNAVAILABLE(503, "服务不可用"),
    GATEWAY_TIMEOUT(504, "网关超时"),


    // ------------------- 自定义业务错误码 (建议分模块) -------------------

    // --- 参数校验错误 (A00xx) ---
    PARAM_VALIDATION_ERROR(10001, "参数校验失败"),
    PARAM_IS_BLANK(10002, "参数为空"),
    PARAM_TYPE_ERROR(10003, "参数类型错误"),
    PARAM_IS_INVALID(10004, "参数无效"),

    // --- 用户相关错误 (B00xx) ---
    USER_NOT_LOGGED_IN(20001, "用户未登录"),
    USER_LOGIN_ERROR(20002, "账号或密码错误"),
    USER_ACCOUNT_FORBIDDEN(20003, "账号已被禁用"),
    USER_NOT_EXIST(20004, "用户不存在"),
    USER_HAS_EXISTED(20005, "用户已存在"),

    // --- 业务逻辑错误 (C00xx) ---
    BUSINESS_ERROR(30001, "业务逻辑异常"),
    INSUFFICIENT_STOCK(30002, "库存不足"),
    ORDER_NOT_FOUND(30003, "订单不存在"),

    // --- 系统/中间件错误 (D00xx) ---
    SYSTEM_ERROR(40001, "系统繁忙，请稍后重试"),
    RPC_ERROR(40002, "远程服务调用失败"),
    DATABASE_ERROR(40003, "数据库操作异常"),
    CACHE_ERROR(40004, "缓存服务异常");


    /**
     * 错误码
     */
    private final int code;

    /**
     * 错误信息
     */
    private final String msg;
}